<div id="main-content">
  <div class="container-fluid">
    <div class="row-fluid">
			<div class="span12">
				<div class="nonboxy-widget">
					<div class="widget-head">
						<h5><i class="black-icons blocks_images"></i><?=$title?></h5>
					</div>
					<div class="widget-content">
						<div class="widget-box">
              <?php print $this->form_eksternal->form_open("", 'class=" form-horizontal well" id="formoutlet"', array("id_detail" => $detail[0]->id_history));
              $kategori = array(
                          1 => "SDM",
                          2 => "Service",
                          3 => "Administrasi",
                          4 => "Promo",
                          5 => "Tools",
                          6 => "IT - Software & Hardware",
                          7 => "Parts",
                          9 => "Lainnya"
                      );
              $kategori_code = array(
                          1 => "SDM",
                          2 => "SRV",
                          3 => "ADM",
                          4 => "PRO",
                          5 => "TOL",
                          6 => "IT",
                          7 => "PRT",
                          9 => "LL"
                      );
              ?>
              <div class="row-fluid">
                    <div class="span6 form-horizontal well tab-pane">
								<fieldset>
									<div class="control-group">
										<label class="control-label">Nomor Ticket</label>
                    <div class="controls">
                      <?php
                      $no_seri = ($this->global_models->get_field("d_history", "MAX(no_seri)", array("bulan_seri" => date("m")))) + 1;
                      if($detail[0]->no_tiket){
                        $code_tiket = $kategori_code[$detail[0]->kategori];
                        $no_tiket = $detail[0]->no_tiket;
                        $tanggal_tiket = $detail[0]->tanggal_buat;
                        $no_seri = $detail[0]->no_seri;
                      }
                      else{
                        $no_tiket = "<span id='code_topic'>SDM</span>-<span id='code_tanggal'>".date("dmY")."</span>-".str_pad($no_seri, 4, '0', STR_PAD_LEFT);
                        $code_tiket = "SDM";
                        $tanggal_tiket = date("Y-m-d");
                      }
                      print $no_tiket;
                      print $this->form_eksternal->form_input("code_tiket", $code_tiket, "id='code_tiket' style='display: none;'");
                      print $this->form_eksternal->form_input("tanggal_tiket", $tanggal_tiket, "id='tanggal_tiket' style='display: none;'");
                      print $this->form_eksternal->form_input("no_tiket", $no_seri, "id='no_tiket' style='display: none;'");
                      ?>
                    </div>
                  </div>
									<div class="control-group">
										<label class="control-label">Outlet</label>
                    <div class="controls">
                      <?php print $this->form_eksternal->form_input('outlet', $this->global_models->get_field("m_outlet", "name", array("id_outlet" => $detail[0]->id_outlet)), 'id="outlet"');
                      print $this->form_eksternal->form_input('id_outlet', $detail[0]->id_outlet, 'id="id_outlet" style="display: none"');
                      ?>
                    </div>
                  </div>
                  <?php
                  if($detail[0]->id_actifity_report){
                    $display = "";
                  }
                  else{
                    $display = 'style="display: none"';
                  }
                  ?>
<!--                  <div class="control-group" <?php print $display?> id="laporan">
										<label class="control-label">Laporan Bulan</label>
                    <div class="controls">
                      <?php print $this->form_eksternal->form_input('actifity_report', $this->global_models->get_field("m_actifity_report", "name", array("id_actifity_report" => $detail[0]->id_actifity_report)), 'id="actifity_report"');
                      print $this->form_eksternal->form_input('id_actifity_report', $detail[0]->id_actifity_report, 'id="id_actifity_report" style="display: none"');
                      ?>
                    </div>
                  </div>-->
									<div class="control-group">
										<label class="control-label">Tanggal</label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_date("tanggal_buat", $detail[0]->tanggal_buat, "tanggal_buat", "", " onSelect : function(dateText){ 
                        var d = new Date(dateText);
                        $('#code_tanggal').text(d.getDate()+''+(d.getMonth()+1)+''+d.getFullYear());
                        $('#tanggal_tiket').val(dateText);
                        },")?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Topic</label>
										<div class="controls">
                      <?php 
                      
                      print $this->form_eksternal->form_dropdown('kategori', $kategori, array($detail[0]->kategori), "id='topic'");
                      if(!$detail[0]->kategori)
                        $detail[0]->kategori = 1;
                      $kategori_class = $this->global_models->get_dropdown("m_kategori_pica", "id_kategori_pica", "name", FALSE, array("kategori" => $detail[0]->kategori));
                      ?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Kategori</label>
										<div class="controls" id='kategori'>
                      <?php print $this->form_eksternal->form_dropdown('id_kategori_pica', $kategori_class, array($detail[0]->id_kategori_pica))?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Sumber</label>
										<div class="controls">
                      <?php 
                      $sumber = array(
                          1 => "Email",
                          2 => "Telphone",
                          3 => "Pesan Singkat",
                      );
                      print $this->form_eksternal->form_dropdown('sumber_info_view', $sumber, array($detail[0]->sumber_info_view));
                      ?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Title Pelapor</label>
										<div class="controls">
                      <?php 
                      $panggilan = array(
                          1 => "Bapak",
                          2 => "Ibu",
                      );
                      print $this->form_eksternal->form_dropdown('panggilan', $panggilan, array($detail[0]->panggilan));
                      ?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Nama Pelapor</label>
										<div class="controls">
                      <?php 
                      print $this->form_eksternal->form_input('nama_pelapor', $detail[0]->nama_pelapor, '');
                      ?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Email Pelapor</label>
										<div class="controls">
                      <?php 
                      print $this->form_eksternal->form_input('email_pelapor', $detail[0]->email_pelapor, '');
                      ?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Telphone Pelapor</label>
										<div class="controls">
                      <?php 
                      print $this->form_eksternal->form_input('telp_pelapor', $detail[0]->telp_pelapor, '');
                      ?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Inisial Respons</label>
										<div class="controls">
                      <?php 
                      print $this->form_eksternal->form_input('inisial_respons', $detail[0]->inisial_respons, 'class="span2"');
                      ?> hari
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Deskripsi</label>
										<div class="controls">
                      <?=$this->form_eksternal->form_textarea('problem', $detail[0]->problem)?>
										</div>
									</div>
								</fieldset>
              </div>
              <div class="span6 form-horizontal well tab-pane">
								<fieldset>
									<div class="control-group">
										<label class="control-label">Tindakan</label>
										<div class="controls">
                      <?=$this->form_eksternal->form_textarea('corrective', $detail[0]->corrective)?>
										</div>
									</div>
<!--                  <div class="control-group">
										<label class="control-label">Start Date</label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_date("tanggal_mulai", $detail[0]->tanggal_mulai, "tanggal_mulai", "")?>
										</div>
									</div>-->
                  <div class="control-group">
										<label class="control-label">Due Date</label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_date("due_date", $detail[0]->due_date, "due_date", "")?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Status</label>
										<div class="controls">
                      <?php 
                      $status = array(
                          0 => "Draft",
                          1 => "Progress",
                          2 => "Finish"
                      );
                      print $this->form_eksternal->form_dropdown('fix', $status, array($detail[0]->fix));
                      ?>
										</div>
									</div>
                  <div class="control-group">
										<label class="control-label">PIC</label>
                    <div class="controls">
                      <?php print $this->form_eksternal->form_input('pic_pica', $this->global_models->get_field("m_pic_pica", "name", array("id_pic_pica" => $detail[0]->id_pic_pica)), 'id="pic_pica"');
                      print $this->form_eksternal->form_input('id_pic_pica', $detail[0]->id_pic_pica, 'id="id_pic_pica" style="display: none"');
                      ?>
                    </div>
                  </div>
								</fieldset>
              </div>
              <?php
              if($detail[0]->id_history){
              ?>
              <div class="span6 form-horizontal well tab-pane">
								<fieldset>
									<div class="control-group">
										<?php
                    print $this->form_eksternal->form_addrow_tr(
                            array("Note", "Tanggal"), 
                            $isi, 
                            site_url("customer-service/addrow-log-pica"), 
                            "items", 
                            "id_items", 
                            "nomor_flag", 
                            $tr, 
                            "width='100%'", false, true, false, $tambah = array())
                    ?>
									</div>
                  <?php print $this->form_eksternal->form_input('param', 1, 'id="nomor_flag" style="display: none;"')?>
								</fieldset>
              </div>
              <?php
              }
              ?>
            </div>
								<div class="form-actions">
									<button class="btn btn-primary" type="submit">Save changes</button>
									<button class="btn" onclick="history.go(-1);return false;">Cancel</button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
  </div>
</div>
<script>
  $(function () {
    $("#cekprivilege").click(function(){
      $("#showprivilege").fadeToggle();
    });
    var person = {1:"SDM", 2:"SRV", 3:"ADM", 4:"PRO", 5:"TOL", 6:"IT", 7:"PRT", 9:"LL"};
    $( "#topic" ).change(function(){
      $( "#pic_pica" ).autocomplete('option', 'source', "<?php print site_url("outlet/tambahan/auto-pic-pica")?>/"+$("#topic").val());
      $("#code_topic").text(person[$("#topic").val()]);
      $("#code_tiket").val(person[$("#topic").val()]);
      $.post('<?php print site_url("customer-service/get-dropdown-kategori/")?>/'+$("#topic").val(),{no:3},function(data){
        $("#kategori").html(data);
      });
    });
    
    $( "#outlet" ).autocomplete({
      source: "<?php print site_url("outlet/tambahan/auto-outlet")?>",
      minLength: 1,
      select: function( event, ui ) {
        console.log(ui);
        $("#id_outlet").val(ui.item.id);
        $("#laporan").show();
        $( "#actifity_report" ).autocomplete('option', 'source', "<?php print site_url("outlet/tambahan/auto-activity/")?>/"+$("#id_outlet").val()+"/");
      }
    });
    $( "#actifity_report" ).autocomplete({
      source: "<?php print site_url("outlet/tambahan/auto-activity")?>",
      minLength: 1,
      select: function( event, ui ) {
        $("#id_actifity_report").val(ui.item.id);
      }
    });
    $( "#pic_pica" ).autocomplete({
      source: "<?php print site_url("outlet/tambahan/auto-pic-pica/".$detail[0]->kategori)?>",
      minLength: 1,
      select: function( event, ui ) {
        $("#id_pic_pica").val(ui.item.id);
      }
    });
    
  });
  
  function del_row_lokal(tr){
    $("#"+tr).remove();
  }
//  $( "p" ).replaceWith( "<b>Paragraph. </b>" );
</script>